@extends('layouts.default') @section('main')
    <link rel="stylesheet" href="/css/uniform.css" />
    <link rel="stylesheet" href="/css/select2.css" />
    <div id="content">
        <div id="content-header">
            <div id="breadcrumb"> <a href="{{url('home')}}" title="返回首页" class="tip-bottom"><i class="icon-home"></i> 首页</a>
                <a href="#" class="tip-bottom">全局管理</a>
                <a href="#" class="current">短信模板管理</a>
            </div>
            <div class="container-fluid">
                <div class="row-fluid">
                    <div class="span12">
                        @if(in_array('add',$actions))<a data-toggle="modal" class="create"
                                                        href="#alert"><button class="btn">新增</button></a>@endif
                        <form action="{{url('smstemplate/search')}}" method="post">
                            <table>
                                <tr>
                                    <th>
                                        <label >标题 :</label>
                                    </th>
                                    <th>
                                        <div class="controls">
                                            <input type="text" class="span11" name="subject" value="" placeholder="标题" />
                                        </div>
                                    </th>
                                    <th>
                                        <label >内容 :</label>
                                    </th>
                                    <th>
                                        <div class="controls">
                                            <input type="text" class="span11" name="content" value="" placeholder="内容" />
                                        </div>
                                    </th>
                                    <th>
                                        <label >是否关联活动 :</label>
                                    </th>
                                    <th>
                                        <div class="controls">
                                            <select  name="related_activity" class="span11" >
                                                <option value="">请选择</option>
                                                <option value="1">关联</option>
                                                <option value="0">不关联</option>
                                            </select>
                                        </div>
                                    </th>
                                    <th>
                                        <label >是否关联项目 :</label>
                                    </th>
                                    <th>
                                        <div class="controls">
                                            <select  name="related_project" class="span11" >
                                                <option value="">请选择</option>
                                                <option value="1">关联</option>
                                                <option value="0">不关联</option>
                                            </select>
                                        </div>
                                    </th>

                                    <th>
                                        <input type="hidden" name="_token" value="{{ csrf_token() }}">
                                        <div class="controls">
                                            <button type="submit" class="btn btn-info">查询</button>
                                        </div>
                                    </th>
                                </tr>
                            </table>
                        </form>
                        <div class="widget-box">
                            <div class="widget-title"> <span class="icon"><i class="icon-th"></i></span>
                                <h5>短信模板管理</h5>
                            </div>
                            <div class="widget-content nopadding">
                                <table class="table table-bordered table-striped">
                                    <thead>
                                    <tr>
                                        <th>标题</th>
                                        <th>内容</th>
                                        <th>内容是否涉及活动</th>
                                        <th>内容是否涉及项目</th>
                                        <th>状态</th>
                                        <th>操作</th>
                                    </tr>
                                    </thead>
                                    <tbody>
                                    @foreach($lists as $k => $v)
                                        <tr class="gradeX">
                                            <td>{{$v->subject}}</td>
                                            <td>{{cut_str($v->content,16)}}</td>
                                            <td>@if($v->related_activity == 1)<i class="icon-ok"></i>@elseif($v->related_activity == 0)<i class="icon-remove"></i>@endif</td>
                                            <td>@if($v->related_project == 1)<i class="icon-ok"></i>@elseif($v->related_project == 0)<i class="icon-remove"></i>@endif</td>
                                            <td>@if($v->status == 1) <i class="icon-ok"></i> @elseif ($v->status == 0) <i class="icon-remove"></i> @endif</td>
                                            <td class="center">
                                                @if(in_array('edit',$actions))<a data-original-title="编辑" class="tip" href="{{url('smstemplate/edit?id='.$v->id)}}"><i class="icon-pencil"></i></a>@endif
                                                @if(in_array('delete',$actions))<a data-original-title="删除" data-toggle="modal" class="tip setting_delete" setting_id="{{$v->id}}" href="#myAlert"><i class="icon-remove"></i></a>@endif
                                            </td>
                                        </tr>
                                    @endforeach
                                    </tbody>
                                </table>
                            </div>
                        </div>
                            <?php echo $lists->appends(['subject' => $subject,'content' => $content,'related_activity' => $related_activity,'related_project' => $related_project])->render();?>
                    </div>
                </div>
            </div>
        </div>
        <div>
            <div id="myAlert" class="modal hide">
                <div class="modal-header">
                    <button data-dismiss="modal" class="close" type="button">×</button>
                    <h3>提示</h3>
                </div>
                <div class="modal-body">
                    <p>确认删除这条数据吗？</p>
                </div>
                <div class="modal-footer">
                    <a data-dismiss="modal" class="btn btn-primary" href="javascript:void(0);">确定</a>
                    <a data-dismiss="modal" class="btn" href="javascript:void(0);">取消</a>
                </div>
            </div>
            <form action="{{url('setting/delete')}}" method="post"
                  id="settingForm">
                <input type="hidden" name="sid" value="0">
            </form>
        </div>

        <div>
            <div id="alert" class="modal hide">
                <div class="modal-header">
                    <button data-dismiss="modal" class="close" type="button">×</button>
                    <h3>提示</h3>
                </div>
                <div class="modal-body">
                    <p>创建新短信模板时，需要向短信运营商提供及时报备，继续创建？</p>
                </div>
                <div class="modal-footer">
                    <a data-dismiss="modal" class="btn btn-create" href="javascript:void(0);">确定</a>
                    <a data-dismiss="modal" class="btn" href="javascript:void(0);">取消</a>
                </div>
            </div>
            <form action="{{url('smstemplate/insert')}}" method="post"
                  id="activityForm">
                <input type="hidden" name="aid" value="0">
            </form>
        </div>

        <script src="/js/jquery.min.js"></script>
        <script src="/js/matrix.tables.js"></script>
        <script src="/js/common.js"></script>

        <script>
            $(".setting_delete").click(function(){
                var setting_id = $(this).attr("setting_id");
                $("input[name='sid']").val(setting_id);
            });
            $(".btn-primary").click(function(){
                var setting_id = $("input[name='sid']").val();
                if(setting_id == 0){
                    alert('参数异常');
                    return;
                }
                ajaxRequest($('#settingForm').serializeArray(),$('#settingForm').attr('action'),function(data){
                    if(data.status){
                        alert(data.message);
                        window.location.href = data.forwardUrl;
                    }else{
                        alert(data.message);
                    }
                });
            });

            $(".btn-create").click(function(){
                window.location.href = "{{url('smstemplate/create')}}";
            });
        </script>
@stop
